package corej.course.thread;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

public class TestAWTEvent {
    public static void main(String[] args) {
        JFrame f = new JFrame("Hello");
        f.setSize(300, 200);
        f.setLayout(new FlowLayout());
        JButton b1 = new JButton("��ť1");
        JButton b2 = new JButton("��ť2");
        f.add(b1);
        f.add(b2);

        f.setVisible(true);

        /*
           * MouseListener l=new MyMouseListener(); b1.addMouseListener(l);
           * b2.addMouseListener(l);
           *
           * b1.addMouseListener(new MyMouseListener2());
           *
           * f.addWindowListener(new MyWindowListener());
           */
        class MyMouseListener implements MouseListener {

            public void mouseClicked(MouseEvent e) {
                System.out.println("�����");
            }

            public void mouseEntered(MouseEvent e) {
                System.out.print("������ ");
                Object o = e.getSource();
                JButton b = (JButton) o;
                String text = b.getText();
                System.out.println(text);
            }

            public void mouseExited(MouseEvent e) {
                System.out.print("����뿪 ");
                Object o = e.getSource();
                JButton b = (JButton) o;
                String text = b.getText();
                System.out.println(text);
            }

            public void mousePressed(MouseEvent e) {
                System.out.println("��갴��ȥ");
            }

            public void mouseReleased(MouseEvent e) {
                System.out.println("���̧��4");
            }
        }

        class MyMouseListener2 extends MouseAdapter {
            public void mouseEntered(MouseEvent e) {
                System.out.print("Mouse���� ");
                Object o = e.getSource();
                JButton b = (JButton) o;
                String text = b.getText();
                System.out.println(text);
            }

            public void mouseExited(MouseEvent e) {
                System.out.print("Mouse�뿪 ");
                Object o = e.getSource();
                JButton b = (JButton) o;
                String text = b.getText();
                System.out.println(text);
            }
        }
        /*
           * f.addWindowListener(new WindowAdapter(){ public void
           * windowClosing(WindowEvent arg0) { System.exit(0); } });
           */
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    }
}
